#! header
snippet #! "Shebang header for groovy scripts" b
#!/usr/bin/env groovy
$0
endsnippet

snippet fo "=~ find operator" 
=~ /${0:regexp}/
endsnippet

snippet map "map" 
[
	${1:key}: ${2:value},${3}
]
endsnippet

snippet // "//" 
// -----------------------------------------------------------------------
//	${1:centent}
// -----------------------------------------------------------------------
endsnippet

snippet clo "closure" 
{ ${1:it} ->
	${0:statement}
}
endsnippet

snippet class 
class ${1:classname} {
	${0}
}
endsnippet

snippet main 
static main(args) {
	${0}
}
endsnippet

snippet mainclass 
public class Main {
	static main(args) {
		${0}
	}
}
endsnippet

#######################################################################
#                            Flow control                             #
#######################################################################

# if
snippet if "if (condition) { ... }"
if(${1:true}) {
${0:${VISUAL}}
}
endsnippet

# if ... else
snippet ife "if (condition) { ... } else { ... }"
if(${1:true}) {
	${0:${VISUAL}}
} else {
	${2}
}
endsnippet

# For in loop
snippet fori
for (${1:e} in ${2:list}) {
	${0:$2[$1]}
}
endsnippet

snippet wh "(condition) { ... }"
while (${1:/* condition */}) {
	${0:${VISUAL}}
}
endsnippet

# tertiary conditional
snippet ter
${1:/* condition */} ? ${2:/* if true */} : ${0:/* if false */}
endsnippet

# switch
snippet switch
switch(${1:expression}) {
	case '${3:case}':
		${4}
		break;
	${0}
	default:
		${2}
}
endsnippet

snippet case "case 'xyz': ... break"
case '${1:case}':
	${0:${VISUAL}}
	break;
endsnippet

snippet try "try { ... } catch(e) { ... }"
try {
	${0:${VISUAL}}
} catch(${1:e}) {
	${2:/* handle error */}
}
endsnippet

snippet tryf "try { ... } catch(e) { ... } finally { ... }"
try {
	${0:${VISUAL}}
} catch (${1:e}) {
	${2:/* handle error */}
} finally {
	${3:/* be executed regardless of the try / catch result*/}
}
endsnippet

#######################################################################
#                             Testing                                 #
#######################################################################


snippet as "assert" b
assert ${1:test}
endsnippet

snippet ae "assertEquals" b
assertEquals ${1:expected}, ${2: actually} 
endsnippet


#######################################################################
#                                 sql                                 #
#######################################################################

snippet sqlcon "sql connection statement" 
def url = 'jdbc:mysql://127.0.0.1:3306/${1:demo}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false'
def user = 'root'
def password = 'root'
def driver = 'com.mysql.jdbc.Driver'

def sql = Sql.newInstance(url, user, password, driver)

${0}
endsnippet


snippet sqlwith "sql connection using withInstance statement" 
def url = 'jdbc:mysql://127.0.0.1:3306/${1:demo}?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=false'
def user = 'root'
def password = 'root'
def driver = 'com.mysql.jdbc.Driver'

Sql.withInstance(url, user, password, driver) { sql ->
	${2:println sql.connection.catalog}
}
${0}
endsnippet
